#define MAX_CANT_ESTRELLAS 3000

#include "ui_estrellas.h"
#include <GL/gl.h>
#include <GL/glu.h>
#include <cmath>

namespace ui {
namespace tablero {
namespace mapa {

Estrellas::Estrellas() {

	double t_dDistancia;
	int t_iCantEstrellas = 0;

	while (t_iCantEstrellas < MAX_CANT_ESTRELLAS) {

		Estrella t_Estrella;

		t_Estrella.x = random(-10.0f, 10.0f);
		t_Estrella.y = random(-10.0f, 10.0f);
		t_Estrella.z = random(-10.0f, 10.0f);

		t_dDistancia = sqrt(sqr(t_Estrella.x) +
			sqr(t_Estrella.y) + sqr(t_Estrella.z));

		if (t_dDistancia > 8.0f) {
			this->m_Estrellas.push_back(t_Estrella);
			++t_iCantEstrellas;
		}
	}
}

Estrellas::~Estrellas() {
}

void Estrellas::dibujar() {
 
	GLUquadric *t_pEstrellaQuad = gluNewQuadric();
	lstEstrellas_t::const_iterator itEstrellas;
	int i = 0;
 
 
	glBegin(GL_POINTS);
	
	for (itEstrellas = this->m_Estrellas.begin(); 
		itEstrellas != this->m_Estrellas.end(); itEstrellas++, i++) {
 
		if (i % 4 == 0) glColor3f(100.0, 0.0, 0.0);
		else if (i % 4 == 1) glColor3f(255.0f, 255.0f, 255.0f);
		else if (i % 4 == 2) glColor3f(0.0, 0.0, 100.0);
		else glColor3f(255.0f, 255.0f, 255.0f);
 
    	glPushMatrix();
		glTranslatef(itEstrellas->x, itEstrellas->y, itEstrellas->z);
		//gluSphere(t_pEstrellaQuad, 0.015, 64, 64);
		glVertex3d(itEstrellas->x, itEstrellas->y, itEstrellas->z);
		glVertex3d(itEstrellas->x + 0.001, itEstrellas->y, itEstrellas->z);
		glVertex3d(itEstrellas->x + 0.002, itEstrellas->y, itEstrellas->z);
		glVertex3d(itEstrellas->x + 0.003, itEstrellas->y, itEstrellas->z);
		glVertex3d(itEstrellas->x - 0.001, itEstrellas->y, itEstrellas->z);
		glVertex3d(itEstrellas->x - 0.002, itEstrellas->y, itEstrellas->z);
		glVertex3d(itEstrellas->x - 0.003, itEstrellas->y, itEstrellas->z);
		glVertex3d(itEstrellas->x, itEstrellas->y + 0.001, itEstrellas->z);
		glVertex3d(itEstrellas->x, itEstrellas->y + 0.002, itEstrellas->z);
		glVertex3d(itEstrellas->x, itEstrellas->y + 0.003, itEstrellas->z);
		glVertex3d(itEstrellas->x, itEstrellas->y - 0.001, itEstrellas->z);
		glVertex3d(itEstrellas->x, itEstrellas->y - 0.002, itEstrellas->z);
		glVertex3d(itEstrellas->x, itEstrellas->y - 0.003, itEstrellas->z);
		glVertex3d(itEstrellas->x, itEstrellas->y, itEstrellas->z + 0.001);
		glVertex3d(itEstrellas->x, itEstrellas->y, itEstrellas->z + 0.002);
		glVertex3d(itEstrellas->x, itEstrellas->y, itEstrellas->z + 0.003);
		glVertex3d(itEstrellas->x, itEstrellas->y, itEstrellas->z - 0.001);
		glVertex3d(itEstrellas->x, itEstrellas->y, itEstrellas->z - 0.002);
		glVertex3d(itEstrellas->x, itEstrellas->y, itEstrellas->z - 0.003);
    	glPopMatrix();
	}
 
	gluDeleteQuadric(t_pEstrellaQuad);
	glEnd();
}

}
}
}
